package pl.perseus.action;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import lombok.Getter;
import lombok.Setter;

import org.springframework.beans.factory.annotation.Autowired;

import pl.perseus.model.Classes;
import pl.perseus.model.Degree;
import pl.perseus.model.Student;
import pl.perseus.service.degree.IDegreeService;

public class GetDegreesForStudentAction extends BaseAction {

	@Getter
	@Setter
	Student student;
	
	@Getter
	@Setter
	Classes classes;
	
	@Autowired
	IDegreeService degreeService;
	
	@Getter
	@Setter
	Map<String, Object> result;
	
	@Override
	public String execute() {
		result = new HashMap<String, Object>();
		
		List<Degree> degrees = degreeService.getDegreesForStudentAndClasses(student, classes);
		List<Map<String, String>> items = new LinkedList<Map<String, String>>();
		
		for(Degree d : degrees){
			Map<String, String> degreeMap = new HashMap<String, String>();
			degreeMap.put("id", d.getId().toString());
			degreeMap.put("name", d.getDegreename()+" "+d.getDegreevalue()+" "+d.getDescription());
			
			items.add(degreeMap);
		}
		
		result.put("identifier", "id");
		result.put("items", items);
		
		return SUCCESS;
	}

}
